﻿var appName = "OSharpApp";
angular.module(appName, ["kendo.directives"]).controller("app.admin.store.customers", ["$scope", function ($scope) {
    $scope.title = "客户信息列表";
    $scope.gridOptions = $.osharp.kendo.grid.Options({
        url: {
            read: "/admin/customers/read",
            create: "/admin/customers/create",
            update: "/admin/customers/update",
            destroy: "/admin/customers/delete"
        },
        model: {
            id: "Id",
            fields: {
                Id: { type: "number", editable: false },
                Name: { type: "string", validation: { required: true } },
                PhoneNumber: { type: "string" },
                CustomerType: { type: "number", validation: { required: true } },
                JiyouId: { type: "number" },
                JiyouName: { type: "string" },
                JiyouGeId: { type: "number" },
                JiyouGeName: { type: "string" },
                NowMilage: { type: "number" },
                NextMilage: { type: "number", editable: false },
                CreatedTime: { type: "date", editable: false }
            }
        },
        columns: [
            { command: [{ name: "destroy", text: "" }], width: 50 },
            { field: "Id", title: "编号", width: 75 },
            { field: "Name", title: "客户名称" },
            { field: "PhoneNumber", title: "手机号" },
            {
                field: "CustomerType", title: "客户类型",
                editor: function (container, options) {
                    $.osharp.kendo.grid.DropDownListEditor(container, options, $.osharp.data.admin.customerTypes);
                },
                template: function (d) { return $.osharp.tools.valueToText(d.CustomerType, $.osharp.data.admin.customerTypes); }
            }, {
                field: "JiyouId",
                title: "机油",
                editor: function (container, options) {
                    $.osharp.kendo.grid.RemoteDropDownListEditor(container, options, "/admin/products/node-read?type=0", "ProductName", "ProductId");
                },
                template: "#=(JiyouName)#"
            }, {
                field: "JiyouGeId",
                title: "机油格",
                editor: function (container, options) {
                    $.osharp.kendo.grid.RemoteDropDownListEditor(container, options, "/admin/products/node-read?type=1", "ProductName", "ProductId");
                },
                template: "#=(JiyouGeName)#"
            },
            { field: "NowMilage", title: "本次里程" },
            { field: "NextMilage", title: "下次里程" },
            { field: "CreatedTime", title: "添加时间", format: "{0: yyyy-MM-dd HH:mm}" }
        ],
        //editable: { mode: "popup", confirmation: true },
        //toolbar: ["create"]
    });
}]);